<?php
set_time_limit(0);
ini_set("display_errors", "On");
error_reporting(E_ALL);
require_once './Classes/PHPExcel.php';
// SELECT a.* FROM `u3` a, u3 b WHERE a.id != b.id  and a.name=b.name;

//$theTxt='{"name":"暴打柠檬三果恋","description":"使用须知： 1.凭此券，可免费兑换一杯新品暴打柠檬三果恋（中杯）。 2.单笔订单中，本券不可累加使用、不可兑换现金、不找零、不与门店其他优惠活动同享，外卖平台及小程序点单不可使用。 3.请在有效期内使用，过期作废。 4.请在兑换券有效期内使用，逾期作废，每个兑换码只能使用一次。若使用兑换券的订单发生退款，将只退还实际付款金额，兑换券不退还。 5.此兑换券仅限购买“15元券包”门店当日使用。","expires_at":"2021-06-23","valid_since":"2021-06-10","promotion":{"name":"暴打柠檬三果恋","vendor_id":"2021053188","discount_ratio":null,"discount_amount":null},"user":{"phone":"18284565834","name":"黄鹃","gender":"female","birthdate":"1988-05-03","city":"成都市","card_number":"9591748531","membership_tier":null}}';
//$theTxt2=json_decode($theTxt,true);

 //var_dump($theTxt2);

//exit;


$objPHPExcel = new PHPExcel();

$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'openid')
            ->setCellValue('B1', '会员号')
            ->setCellValue('C1', '时间')
;
include '../c/config.php';

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, 'klnm');
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
 
function trimall($str) 
{
    $qian=array(" ","　","\t","\n","\r");
    $hou=array("","","","","");
    return str_replace($qian,$hou,$str); 
}
 
//SELECT idcard,COUNT(*) FROM download GROUP BY idcard HAVING COUNT(*) > 1
//SELECT DISTINCT(idcard) FROM download  1213+17602 

$sql="SELECT openid,createtime,idcard FROM `download`  ";
$query =$mysqli->query($sql);
$index=2;
while ($list=$query->fetch_array()){
 
           $cardNo=$list['idcard'];
           if('seimsong' == $cardNo){
           	   $cardNo='';
           }
		    $objPHPExcel->setActiveSheetIndex(0)
		    ->setCellValue('A'.$index, $list['openid'])
		    ->setCellValue('B'.$index, $cardNo)
		    ->setCellValue('C'.$index, $list['createtime'].' ')
		    ;
		    $index++;	
	    

	 
}
 
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('用户名单');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename=用户名单.xlsx');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
